<?php

namespace app\admin\controller\yunfood;

use addons\yunfood\library\Backend;
use app\admin\model\yunfood\Page;
use app\admin\model\yunfood\Food;

/**
 * 通用处理
 */
class Common extends Backend
{
    protected $noNeedRight = ['typeModel'];

    /**
     * 联动搜索
     */
    public function typeModel()
    {
        $group = $this->request->get('group');
        $source = $this->request->get('source');

        $list = [];
        if ($group === 'type') {
            foreach (['page' => '单页', 'goods' => '商品'] as $key => $value) {
                $list[] = ['value' => $key, 'name' => $value];
            }
        } elseif ($group === 'model') {
            if ($source === 'page') {
                $list = Page::field('id as value, name')->select();
            } elseif ($source === 'food') {
                $list = Food::field('id as value, name')->where($this->getShopWhere())->select();
            }
        }
        $this->success('', null, $list);
    }

    public function index()
    {
        return;
    }

    public function add()
    {
        return;
    }

    public function edit($ids = null)
    {
        return;
    }

    public function del($ids = null)
    {
        return;
    }

    public function multi($ids = null)
    {
        return;
    }
}
